package com.khalil.kkadmin.infrastructure.web;

import com.khalil.kkadmin.common.exception.BusinessException;
import com.khalil.kkadmin.common.web.RespResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class ResultResponseControllerAdvice {

    @ExceptionHandler(value = {BusinessException.class})
    public RespResult<Void> handleBusinessException(BusinessException e) {
        log.error("Exception: ", e);
        return RespResult.error(e.getCode(), e.getMsg());
    }

    @ExceptionHandler(value = {Exception.class})
    public RespResult<Void> handleException(Exception e) {
        log.error("Exception: ", e);
        return RespResult.error(e.getMessage());
    }
}
